package mlz.e_method;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/*
    获取方法的应用
 */
public class MethodDemo02 {
    public static void main(String[] args) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        //获取类的字节码对象
        Class<Student> c = Student.class;

        //获取方法
        Method method = c.getMethod("function4", String.class);

        //操作方法 -> invoke -> 运行方法
        Student stu= c.newInstance();
        //如果是私有方法,设置一下访问权限
        //method.setAccessible(true);
        Object o = method.invoke(stu, "lucy");
        System.out.println(o);


    }
}
